<?php include PATH_VIEWS . 'common/header.php'; ?>
<div class="main">
    <?php include PATH_VIEWS . 'common/left.php'; ?>
    <div class="main_right welcome_right" id="slide">
        <dl>
            <dt><h3>操作说明 <span>[关闭/展开]</span></h3></dt>
            <dd class="border">
                <span>以下红色边框的表单是必填项 。</span>
            </dd>
        </dl>
        <dl>
            <dt class="bottom">
            <h4>添加商品</h4>
            </dt>
            <dd>
                <form id="form1" name="form1" method="post" enctype="multipart/form-data" action="<?php echo URL; ?>">
                    <table class="system_envir from_demo"> 
                        <tr>
                            <td>上级菜单名称</td>
                            <td class="sanji">
                                <select name="FcateIds[]" onchange="getMenu(this.value)">
                                    <option value="0">顶级</option>
                                    <?php foreach ($menu_list as $ls) { ?>
                                        <option value="<?php echo $ls['Fid']; ?>" <?php echo ($ls['Fid'] == $cate_id) ? "selected=selected" : ''; ?> ><?php echo $ls['Fname']; ?></option>
                                    <?php } ?>
                                </select>
                                <select id="showMenu" name="FcateIds[]" class="hide" onchange="getSub(this.value)">
                                    <?php
                                    if (isset($cate_two_menu)) {
                                        foreach ($cate_two_menu as $ls1) {
                                            ?>
                                            <option value="<?php echo $ls1['Fid']; ?>" <?php echo ($ls1['Fid'] == $two_id) ? "selected=selected" : ''; ?>><?php echo $ls1['Fname']; ?></option>
                                        <?php } ?>
                                    <?php } ?>
                                </select>
                                <select id="subMenu" name="FcateIds[]" class="hide">
                                    <?php
                                    if (isset($cate_three_menu)) {
                                        foreach ($cate_three_menu as $ls2) {
                                            ?>
                                            <option value="<?php echo $ls2['Fid']; ?>" <?php echo ($ls2['Fid'] == $three_id) ? "selected=selected" : ''; ?>><?php echo $ls2['Fname']; ?></option>
                                        <?php } ?>
                                    <?php } ?>
                                </select>
                            </td>
                            <td></td>
                        </tr>
                        <tr class="email">
                            <td>商品标题</td>
                            <td><input type="text" id="menuVal" name="Ftitle" value="<?php echo $edit['Ftitle']; ?>" maxlength="16" style="width: 80%" data-rule="商品标题:required;length[2~64]" data-target="#tiShi"/></td>
                            <td id="tiShi">在填写商品名称时，请注意简短且要具有概括性。字符长度：2-16个</td>
                        </tr>
                        <tr>
                            <td>商品子标题</td>
                            <td><input type="text" id="menuVal" name="Fstitle" value="<?php echo $edit['Fstitle']; ?>" maxlength="16" style="width: 80%"/></td>
                            <td>在填写商品名称时，请注意简短且要具有概括性。字符长度：2-16个</td>
                        </tr>
                        <tr>
                            <td>商品英文名</td>
                            <td><input type="text" id="menuVal" name="FenTitle" value="<?php echo $edit['FenTitle']; ?>" maxlength="16" style="width: 80%"/></td>
                            <td>在填写商品名称时，请注意简短且要具有概括性。字符长度：2-16个</td>
                        </tr>
                        <tr>
                            <td>商品主图</td>
                            <td><input type="file" id="sort" name="Fimg" style="width:auto"/></td>
                            <td class="tishi">产品的主图</td>
                        </tr>
                        <tr>
                            <td>商品分类信息</td>
                            <td>
                                <select name="FinfoIds[]">
                                    <option value="0">选择商品品牌</option>
                                    <?php foreach ($info_list_array[1] as $ls) { ?>
                                        <option value="<?php echo $ls['Fid']; ?>" <?php echo (in_array($ls['Fid'], $info_id_arrs)) ? "selected" : ''; ?>><?php echo $ls['Fname']; ?></option>
                                    <?php } ?>
                                </select>
                                <select name="FinfoIds[]">
                                    <option value="0">选择商品产地</option>
                                    <?php foreach ($info_list_array[3] as $ls) { ?>
                                        <option value="<?php echo $ls['Fid']; ?>" <?php echo (in_array($ls['Fid'], $info_id_arrs)) ? "selected" : ''; ?> ><?php echo $ls['Fname']; ?></option>
                                    <?php } ?>
                                </select>
                                <select name="FinfoIds[]">
                                    <option value="0">选择商品包装</option>
                                    <?php foreach ($info_list_array[4] as $ls) { ?>
                                        <option value="<?php echo $ls['Fid']; ?>" <?php echo (in_array($ls['Fid'], $info_id_arrs)) ? "selected" : ''; ?>><?php echo $ls['Fname']; ?></option>
                                    <?php } ?>
                                </select>
                            </td>
                            <td id="tishix">字符为2-16个字</td>
                        </tr>
                        <tr>
                            <td>商品分类信息</td>
                            <td>
                                <select name="FinfoIds[]">
                                    <option value="0">选择商品功效</option>
                                    <?php foreach ($info_list_array[6] as $ls) { ?>
                                        <option value="<?php echo $ls['Fid']; ?>" <?php echo (in_array($ls['Fid'], $info_id_arrs)) ? "selected" : ''; ?>><?php echo $ls['Fname']; ?></option>
                                    <?php } ?>
                                </select>
                                <select name="FinfoIds[]">
                                    <option value="0">选择商品使用肤质</option>
                                    <?php foreach ($info_list_array[7] as $ls) { ?>
                                        <option value="<?php echo $ls['Fid']; ?>" <?php echo (in_array($ls['Fid'], $info_id_arrs)) ? "selected" : ''; ?>><?php echo $ls['Fname']; ?></option>
                                    <?php } ?>
                                </select>
                                <select name="FinfoIds[]">
                                    <option value="0">选择商品适合的肤龄</option>
                                    <?php foreach ($info_list_array[8] as $ls) { ?>
                                        <option value="<?php echo $ls['Fid']; ?>" <?php echo (in_array($ls['Fid'], $info_id_arrs)) ? "selected" : ''; ?>><?php echo $ls['Fname']; ?></option>
                                    <?php } ?>
                                </select>
                            </td>
                            <td id="tishix">字符为2-16个字</td>
                        </tr>
                        <tr>
                            <td>商品分类信息</td>
                            <td>
                                <select name="FinfoIds[]">
                                    <option value="0">选择商品规格</option>
                                    <?php foreach ($info_list_array[5] as $ls) { ?>
                                        <option value="<?php echo $ls['Fid']; ?>" <?php echo (in_array($ls['Fid'], $info_id_arrs)) ? "selected" : ''; ?>><?php echo $ls['Fname']; ?></option>
                                    <?php } ?>
                                </select>
                                <select name="FinfoIds[]">
                                    <option value="0">选择香水香调</option>
                                    <?php foreach ($info_list_array[9] as $ls) { ?>
                                        <option value="<?php echo $ls['Fid']; ?>" <?php echo (in_array($ls['Fid'], $info_id_arrs)) ? "selected" : ''; ?>><?php echo $ls['Fname']; ?></option>
                                    <?php } ?>
                                </select>
                            </td>
                            <td id="tishix">字符为2-16个字</td>
                        </tr>
                        <tr>
                            <td>商品附图</td>
                            <td>
                                <form method="post" enctype="multipart/form-data" >
                                    <div id="queue"></div>
                                    <input id="file_upload" name="file_upload" type="file" multiple="true">
                                </form>
                            </td>
                            <td class="tishi">产品的附图</td>
                        </tr>
                        <tr>
                            <td>商品市场价格</td>
                            <td><input class="border_red" type="text" id="sort" name="Fprice" value="<?php echo $edit['Fprice']; ?>" maxlength="10" data-rule="商品价格:required:integer;length[1~5]" data-target="#tishij"/></td>
                            <td id="tishij">产品的市场价格，不是产品的实际价格</td>
                        </tr>
                        <tr>
                            <td>商品实际价格</td>
                            <td><input type="text" id="sort" name="Fdiscount" value="<?php echo $edit['Fdiscount']; ?>" maxlength="10"/></td>
                            <td class="tishi">商品的实际价格，折扣算出来</td>
                        </tr>
                        <tr>
                            <td>商品运费</td>
                            <td><input type="text" id="sort" name="Fpostage" value="<?php echo $edit['Fpostage']; ?>" maxlength="10"/></td>
                            <td class="tishi">商品的运费，0为包邮</td>
                        </tr>
                        <tr>
                            <td>产品总数量</td>
                            <td><input type="text" id="sort" name="FproudctNum" value="<?php echo $edit['FproudctNum']; ?>" maxlength="5"/></td>
                            <td class="tishi">产品的总数量</td>
                        </tr>
                        <tr>
                            <td>排序</td>
                            <td class="sort"><input type="text" id="sort" name="Fsort" value="<?php echo $edit['Fsort']; ?>" maxlength="2"/></td>
                            <td class="tishi">数值越小，排列越前，数值大小范围：1-99</td>
                        </tr>
                        <tr>
                            <td>商品描述</td>
                            <td colspan="2" style="padding: 5px">
                                <script type="text/javascript" src="<?php echo HTTP_EXTENDS; ?>ueditor1/ueditor.config.js"></script>
                                <!-- 编辑器源码文件 -->
                                <script type="text/javascript" src="<?php echo HTTP_EXTENDS; ?>ueditor1/ueditor.all.js"></script>
                                <!-- 实例化编辑器 -->
                                <script id="edit" name="Fdetails" type="text/plain"><?php echo $edit['Fdetails']; ?></script>
                            </td>                           
                        </tr>
                        <tr>
                            <td>是否为限时抢购</td>
                            <td>
                                <select name="FlimitBuy" style="width: 60px">
                                    <option value="0" <?php echo ($edit['FlimitBuy'] == 0) ? "selected" : ''; ?> >否</option>                           
                                    <option value="1" <?php echo ($edit['FlimitBuy'] == 1) ? "selected" : ''; ?> >是</option>
                                </select>
                            </td>
                            <td>商品状态，决定商品是否可以购买</td>
                        </tr>
                        <tr>
                            <td></td>
                            <td class="subbtn" colspan="2">
                                <input class="ok" type="submit" name="ok" value="确认提交">
                                <a href="javascript:void(0)" onclick="history.back()" class="cancel">返回</a>
                            </td>
                        </tr>
                    </table>
                </form>
            </dd>
        </dl>
        <div id="test"></div>
    </div>
</div>
<?php include PATH_VIEWS . 'common/footer.php'; ?>
<script>
    function getMenu(parent_id) {
        if (parent_id == "0" || parent_id == "") {
            $("#showMenu").addClass("hide");
        } else {
            $("#showMenu").removeClass("hide");
        }

//    取二级菜单
        $.get('index.php?C=Web&A=menuGrade&pid=' + parent_id, function (data) {
            $('#showMenu').html(data);
        });
    }
    function getSub(sub_id) {
        if (sub_id == "0" || sub_id == "") {
            $("#subMenu").addClass("hide");
        } else {
            $("#subMenu").removeClass("hide");
        }
        //    取三级菜单
        $.get('index.php?C=Web&A=menuSub&pid=' + sub_id, function (data) {
            $('#subMenu').html(data);
        });
    }
    var level = <?php echo $level; ?>;
    function showMenu() {
        if (level <= 2) {
            $("#showMenu").addClass('hide');
        } else {
            $("#showMenu").removeClass('hide');
        }
        if (level <= 3) {
            $("#subMenu").addClass('hide');
        } else {
            $("#subMenu").removeClass('hide');
        }

    }
    showMenu();
</script>
<script type="text/javascript">

    $("#file_upload").uploadify({
        'fileSizeLimit': '3MB',
        'successTimeout': 10,
        'height': 50,
        'width': 200,
        'fileTypeDesc': '上传文件中有不支持的的类型，只能上传图片',
        'fileTypeExts': '*.gif; *.jpg;*.jpeg; *.png; *.bmp',
        'queueSizeLimit': 10,
        'buttonText': '<span class="iconfont" style="font-size:20px;"> 请选择附图</span>',
        'overrideEvents': ['onSelectError', 'onDialogClose'],
        'swf': '<?php echo HTTP_EXTENDS; ?>uploadify/uploadify.swf',
        'uploader': 'index.php?C=Web&A=proudctUploadImg&primarykey=<?php echo $pid; ?>',
        'onSelectError': function (file, errorCode, errorMsg) {
            switch (errorCode) {
                case -100:
                    alert("对不起，您一次最多只能上传" + $('#file_upload').uploadify('settings', 'queueSizeLimit') + "个文件！");
                    break;
                case -110:
                    alert("文件 [" + file.name + "] 大小超出系统限制的" + $('#file_upload').uploadify('settings', 'fileSizeLimit') + "大小！");
                    break;
                case -120:
                    alert("文件 [" + file.name + "] 大小异常！");
                    break;
                case -130:
                    alert("文件 [" + file.name + "] 类型不正确！");
                    break;
            }
            return false;
        },
        //检测FLASH失败调用
        'onFallback': function () {
            alert("您未安装FLASH控件，无法上传！请安装FLASH控件后再试。");
        },
//            'onUploadStart': function (file) {
//                $('#progress').append('<li>正在上传图片：' + file.name + '</li>');
//            },
//            'onUploadSuccess': function (file, data, response) {
//                upload_num++;
//                $('#progress').append('<li class="color_green">第[' + upload_num + ']张图片：[' + file.name + ']上传成功！</li>');
//            },
        'onUploadError': function (file, errorCode, errorMsg, errorString) {
            $('#progress').append('<li>图片：' + file.name + '不能成功上传</li>');
            //alert(errorCode);
            //alert(errorMsg);
            //alert(errorString);
            alert('上传失败，文件名：' + file.name);
        },
        'onQueueComplete': function (queueData) {
            $('#file_upload-queue').append('<h3 class="color_green" style="text-align:center">您本次一共成功上传了【' + queueData.uploadsSuccessful + '】张图片！</h3>');
            //刷新页面
//            refrashThisPage();
        }
    });

    //上传成功后，定时刷新本页面
//    function refrashThisPage() {
//        setTimeout(, 3000);
//    }
    var ue = UE.getEditor('edit', {
        emotionLocalization: true,
        maximumWords: 1000,
        initialFrameWidth: 1000,
        initialFrameHeight: 200,
    });
</script>